<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户权限修改</title>
    <script src="../static/js/jquery.min.js"></script>
</head>
<body>
<dev align="center">
    <h2>用户权限修改</h2>
    <table align="center">
        <tr>
            <td>用户名： <input type="text" id="username" th:value="${user.getUsername()}" disabled></td>
        </tr>
        <tr>
            <td>用户权限:
                <select id="roles">
                    <option th:selected="${user.getRoles()} == 'User'">User</option>
                    <option th:selected="${user.getRoles()} == 'Manager'">Manager</option>
                    <option th:selected="${user.getRoles()} == 'Admin'">Admin</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <button onclick="updateUser()">确认更改</button>
            </td>
        </tr>
    </table>
</dev>
</body>
<script type="text/javascript">
    var updateUser = function () {
        var username = $("#username").val();
        var roles = $("#roles").val();
        var data = {
            'username':username,
            'roles':roles
        };
        $.ajax({
            url: '/api/account/update',
            data: JSON.stringify(data),
            dataType: 'JSON',
            type: 'POST',
            contentType : "application/json",
            success: function (res) {
                if (res.code == 100) {
                    window.location.href = "/api/account/index2";
                }else {
                    alert(res.message);
                }
            }
        })
    }
</script>
</html>